import request from '@/utils/request'
import { PageQuery } from '@/api/types'

export interface ContractVO {
  contractId: number
  orderId: number
  orderNo: string
  userId: number
  contractType: string
  contractTitle: string
  contractNo: string
  contractContent: string
  contractAmount: number
  loanAmount: number
  totalRepayment: number
  periods: number
  interestRate: number
  signatureData: string
  signatureTime: string
  signatureIp: string
  status: string
  createTime: string
  updateTime: string
}

export interface ContractQuery extends PageQuery {
  contractNo?: string
  orderNo?: string
  status?: string
  beginSignatureTime?: string
  endSignatureTime?: string
}

// 查询合同列表
export function listContract(query: ContractQuery) {
  return request({
    url: '/beauty/contract/list',
    method: 'get',
    params: query
  })
}

// 查询合同详情
export function getContract(contractId: number) {
  return request({
    url: '/beauty/contract/' + contractId,
    method: 'get'
  })
}

// 根据订单ID查询合同
export function getContractByOrderId(orderId: number) {
  return request({
    url: '/beauty/contract/byOrder/' + orderId,
    method: 'get'
  })
}

// 导出合同PDF
export function exportContractPdf(contractId: number) {
  return request({
    url: '/beauty/contract/exportPdf/' + contractId,
    method: 'get',
    responseType: 'blob'
  })
}

// 删除合同
export function delContract(contractIds: number | number[]) {
  return request({
    url: '/beauty/contract/' + contractIds,
    method: 'delete'
  })
}
